﻿using BacklogParser.Models;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace BacklogParser.Parsers
{
    public static class ClassificationIpcrParser
    {
        public static List<ClassificationIpcr> Parse(XElement claims)
        {
            var priorityClaims = claims.Descendants(Constants.Epo + "classification-ipcr").ToList();
            return ParseClassificationIpcr(priorityClaims);
        }

        private static List<ClassificationIpcr> ParseClassificationIpcr(List<XElement> priorityClaims)
        {
            var result = new List<ClassificationIpcr>();

            foreach (var item in priorityClaims)
            {
                var applicant = new ClassificationIpcr
                {
                     Id = item.Attribute("id").Value,
                     Text = item.Descendants(Constants.Epo + "text").First().Value,
                };

                result.Add(applicant);
            }

            return result;
        }
    }
}
